package com.leyou.sms.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@EnableConfigurationProperties(SmsProperties.class)  //读取SmsProperties
public class SmsConfiguration {

    /**
     * 将阿里云短信发送要使用的类注入到spring容器中
     * 默认单例
     * @param smsProperties
     * @return
     */
    @Bean
    public IAcsClient acsClient(SmsProperties smsProperties) {
        DefaultProfile profile = DefaultProfile.getProfile(
                smsProperties.getRegionId(),
                smsProperties.getAccessKeyId(),
                smsProperties.getAccessSecret());
        return new DefaultAcsClient(profile);
    }
}
